package LeetCode;

import java.util.ArrayList;
import java.util.Arrays;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/5/4.
//
//https://leetcode.cn/problems/remove-duplicates-from-sorted-array/submissions/529120700/
public class 删除有序数组中的重复项 {
    public static void main(String[] args) {
        int[] nums = {0,0,1,1,1,2,2,3,3,4};
        System.out.println(removeDuplicates(nums));
        System.out.println(Arrays.toString(nums));
    }
    public static int removeDuplicates(int[] nums) {
        int n = 1,p = 0;
        for (int i = 1; i < nums.length; i++) {
            if(nums[p] != nums[i]){
                nums[++p] = nums[i];
                n++;
            }
        }
        return n;
    }
}
